package jpa.service.promis.construction;

import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import org.apache.log4j.Logger;
import promis.utility.CommonService;
import jpa.entitys.common.CommonEntity;
import jpa.entitys.promis.construction.CostBoq;
import jpa.entitys.promis.construction.CostBoqPK;
import jpa.service.common.JPAService;

public class CostBoqServices extends JPAService {
	
	private static final Logger log = Logger.getLogger(CostBoqServices.class);

	public CostBoqServices(EntityManager em) {
		super(em);
	}

	public CostBoq findById(CostBoqPK id) throws Exception { 
		return super.ConvertToYoureObject(super.find(id, "CostBoq.findById"));				
	}
	
	public CostBoq Inserted(CostBoq vlaue) throws Exception {
		CostBoq obj = vlaue;
		try{
			
			if(CommonService.IsNull(obj.getLastUpdOn()))
				super.inserted(obj);
			
		}catch(Exception e)
		{
			System.out.println(e.getMessage());
			log.error(e.getMessage());
			throw e;
		}
		return obj;
	}
	
	public CostBoq Updated(CostBoq vlaue) throws Exception {
		CostBoq obj = vlaue;
		try{
			if(vlaue.getId() != null)
				super.updated(obj);
			
		}catch(Exception e)
		{
			System.out.println(e.getMessage());
			log.error(e.getMessage());
			throw e;
		}
		return obj;
	}
	
	public List<CostBoq> Inserted(List<CostBoq> vlauelist) throws Exception {
		try{
			List<CommonEntity> common_lst = new ArrayList<CommonEntity>();			
			for(CostBoq obj : vlauelist)
			{
				if(!CommonService.IsNull(obj.getId()))
					common_lst.add(obj);
			}		
			
			super.inserted(common_lst);
				
		}catch(Exception e)
		{
			System.out.println(e.getMessage());
			log.error(e.getMessage());
			throw e;
		}
		return vlauelist;
	}
	
	public List<CostBoq> Updated(List<CostBoq> vlauelist) throws Exception {
		try{
			List<CommonEntity> common_lst = new ArrayList<CommonEntity>();
			for(CostBoq obj : vlauelist)
				common_lst.add(obj);
			
			super.updated(common_lst);
			
		}catch(Exception e)
		{
			System.out.println(e.getMessage());
			log.error(e.getMessage());
			throw e;
		}
		return vlauelist;
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try{
			
			
			
		}catch(Exception e){
			log.error(e.getMessage());
			System.out.println(e.getMessage());
		}
	}

}
